<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo,">










<meta name="description" content="Hexo是一个比较流行的博客框架，使用Hexo可以轻松搭建一个属于自己的博客。本文记录一下我自己通过Hexo+码云（Gitee）搭建博客的过程以及备份、恢复博客的方法。 环境准备使用Linux系统来搭建更为方便，下面以Windows系统为例进行说明。 安装NodeJS">
<meta name="keywords" content="Hexo">
<meta property="og:type" content="article">
<meta property="og:title" content="HEXO+Gitee搭建博客、备份、恢复">
<meta property="og:url" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/index.html">
<meta property="og:site_name" content="VOSAMO">
<meta property="og:description" content="Hexo是一个比较流行的博客框架，使用Hexo可以轻松搭建一个属于自己的博客。本文记录一下我自己通过Hexo+码云（Gitee）搭建博客的过程以及备份、恢复博客的方法。 环境准备使用Linux系统来搭建更为方便，下面以Windows系统为例进行说明。 安装NodeJS">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/nodejs.jpg">
<meta property="og:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/nodehome.jpg">
<meta property="og:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/newbranch.jpg">
<meta property="og:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/gitpage.jpg">
<meta property="og:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/gitpage2.jpg">
<meta property="og:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/pubkey.jpg">
<meta property="og:updated_time" content="2019-03-28T01:25:20.088Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="HEXO+Gitee搭建博客、备份、恢复">
<meta name="twitter:description" content="Hexo是一个比较流行的博客框架，使用Hexo可以轻松搭建一个属于自己的博客。本文记录一下我自己通过Hexo+码云（Gitee）搭建博客的过程以及备份、恢复博客的方法。 环境准备使用Linux系统来搭建更为方便，下面以Windows系统为例进行说明。 安装NodeJS">
<meta name="twitter:image" content="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/nodejs.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://vosamo.gitee.io/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/">





  <title>HEXO+Gitee搭建博客、备份、恢复 | VOSAMO</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">VOSAMO</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://vosamo.gitee.io/blog/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="vosamo">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="VOSAMO">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">HEXO+Gitee搭建博客、备份、恢复</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-16T15:02:02+08:00">
                2019-02-16
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Hexo/" itemprop="url" rel="index">
                    <span itemprop="name">Hexo</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Hexo是一个比较流行的博客框架，使用Hexo可以轻松搭建一个属于自己的博客。本文记录一下我自己通过Hexo+码云（Gitee）搭建博客的过程以及备份、恢复博客的方法。</p>
<h1 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h1><p>使用Linux系统来搭建更为方便，下面以Windows系统为例进行说明。</p>
<h2 id="安装NodeJS"><a href="#安装NodeJS" class="headerlink" title="安装NodeJS"></a>安装NodeJS</h2> <a id="more"></a>
<p>通过<a href="https://nodejs.org/en/download/" target="_blank" rel="noopener">Node官网</a>下载NodeJS安装包。根据自己的系统选择对应版本的安装文件，然后默认安装。我选择Windows 64位的msi安装包下载：</p>
<img src="/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/nodejs.jpg" title="NodeJS下载">
<p>安装完成之后通过cmd命令行输入<code>node -v</code>验证是否安装成功，如果没有打印出版本信息，需要设置一下系统环境变量。依次选择<code>我的电脑</code>，<code>属性</code>，<code>高级系统设置</code>，<code>高级</code>，<code>环境变量</code>，新建NODE_HOME变量如下，变量值填写“C:\Program Files\nodejs”，即你的NodeJS安装目录。</p>
<img src="/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/nodehome.jpg" title="NODE环境变量">
<p>然后编辑Path变量，添加“%NODE_HOME%”和“%NODE_HOME%\node-global”，然后验证是否安装成功。</p>
<h2 id="安装Git"><a href="#安装Git" class="headerlink" title="安装Git"></a>安装Git</h2><p>Linux系统：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install git</span><br></pre></td></tr></table></figure>
<p>Windows系统：</p>
<p>通过<a href="https://git-scm.com/download/win" target="_blank" rel="noopener">Git官网</a>下载安装包安装。</p>
<p>安装完成之后进行初始化设置，设置git用户名和邮箱：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.email <span class="string">"abc@123.com"</span></span><br><span class="line">git config --global user.name <span class="string">"abc"</span></span><br></pre></td></tr></table></figure>
<h2 id="安装Hexo"><a href="#安装Hexo" class="headerlink" title="安装Hexo"></a>安装Hexo</h2><p>通过node命令安装Hexo：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g hexo</span><br></pre></td></tr></table></figure>
<p>如果要向远端部署的话，还需要安装<code>hexo-deployer-git</code>插件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-deployer-git</span><br></pre></td></tr></table></figure>
<p>安装完成后执行<code>hexo</code>命令，如果能输出如下内容，表示hexo安装成功。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">$ hexo</span><br><span class="line">Usage: hexo &lt;<span class="built_in">command</span>&gt;</span><br><span class="line"></span><br><span class="line">Commands:</span><br><span class="line">  clean     Remove generated files and cache.</span><br><span class="line">  config    Get or <span class="built_in">set</span> configurations.</span><br><span class="line">  deploy    Deploy your website.</span><br><span class="line">  generate  Generate static files.</span><br><span class="line">  <span class="built_in">help</span>      Get <span class="built_in">help</span> on a <span class="built_in">command</span>.</span><br><span class="line">  init      Create a new Hexo folder.</span><br><span class="line">  list      List the information of the site</span><br><span class="line">  migrate   Migrate your site from other system to Hexo.</span><br><span class="line">  new       Create a new post.</span><br><span class="line">  publish   Moves a draft post from _drafts to _posts folder.</span><br><span class="line">  render    Render files with renderer plugins.</span><br><span class="line">  server    Start the server.</span><br><span class="line">  version   Display version information.</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<p>至此，本地环境准备完毕。</p>
<h1 id="创建博客项目"><a href="#创建博客项目" class="headerlink" title="创建博客项目"></a>创建博客项目</h1><h2 id="申请注册码云账号。"><a href="#申请注册码云账号。" class="headerlink" title="申请注册码云账号。"></a>申请注册<a href="https://gitee.com" target="_blank" rel="noopener">码云</a>账号。</h2><h2 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h2><p>创建一个仓库，名为blog（仓库名随意），然后选择默认设置，如果你不想公开自己的项目，你可以将“是否开源”设置为“私有”。</p>
<p>创建新分支hexo，并将hexo分支设置为默认分支。这样项目就有两个分支：</p>
<ul>
<li><p>master分支：保存Hexo编译生成的博客静态文件</p>
</li>
<li><p>hexo分支：保存博客的源文件</p>
</li>
</ul>
<img src="/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/newbranch.jpg" title="创建hexo分支">
<h2 id="开启Page服务"><a href="#开启Page服务" class="headerlink" title="开启Page服务"></a>开启Page服务</h2>  <img src="/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/gitpage.jpg">
  <img src="/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/gitpage2.jpg">
<p>  开启服务之后，会得到一个博客地址，如图中所示，后面配置文件中会用到这个地址。</p>
<h2 id="配置SSH"><a href="#配置SSH" class="headerlink" title="配置SSH"></a>配置SSH</h2><ul>
<li><p>生成秘钥</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ssh-keygen -t rsa -C <span class="string">"abc@123.com"</span></span><br></pre></td></tr></table></figure>
<p>生成秘钥的邮箱需要填写登录gitee的邮箱。</p>
</li>
<li><p>配置秘钥</p>
<p>windows系统在你的<code>C:\Users\xxx\.ssh</code>目录下面会有生成的秘钥对文件，如果你生成秘钥的时候没有填写名称，生成的密钥对名称为<code>id_rsa</code>，其中<code>id_rsa.pub</code>是公钥文件，拷贝公钥的所有内容，打开gitee的秘钥设置，将公钥内容填入：</p>
<img src="/blog/2019/02/16/HEXO-Gitee搭建博客、备份、恢复/pubkey.jpg">
</li>
</ul>
<h2 id="创建博客"><a href="#创建博客" class="headerlink" title="创建博客"></a>创建博客</h2><ul>
<li><p>克隆项目</p>
<p>之前已经配置过ssh秘钥，使用<code>git clone</code>命令将项目克隆到本地一个空文件夹：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> git@gitee.com:vosamo/blog.git</span><br></pre></td></tr></table></figure>
<p>  ​<br>切换进入项目根目录，此时应当处于默认的hexo分支下面：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> blog/</span><br><span class="line"></span><br><span class="line">liushaolin@liushaolin00 MINGW64 /f/myblog/blog (hexo)</span><br></pre></td></tr></table></figure>
</li>
<li><p>初始化</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 初始化 hexo 目录</span></span><br><span class="line">hexo init</span><br><span class="line"><span class="comment"># 安装插件</span></span><br><span class="line">npm install</span><br></pre></td></tr></table></figure>
<p>查看一下都生成了哪些文件：</p>
<ul>
<li>.gitignore：项目忽略文件，需要备份</li>
<li>_config.yml：站点配置文件，需要备份</li>
<li>package.json：安装包文件，需要备份</li>
<li>package-lock.json：安装包文件，需要备份</li>
<li>scaffolds/：博客文章模板，需要备份</li>
<li>source/：博客文章markdown源文件，需要备份</li>
<li>themes/：博客主题目录，需要备份</li>
<li>.deploy_git/：hexo g生成，不需要备份</li>
<li>.git/：标志git项目，不需要备份</li>
<li>db.json：不需要备份</li>
<li>node_modules/：安装包目录，npm install生成，不需要备份</li>
<li>public/：博客静态页面，hexo g生成，不需要备份</li>
</ul>
</li>
<li><p>修改站点配置文件</p>
<p>我们先修改一些基本配置，包括title、author、language、url、root、deploy等配置项。可以查看<a href="https://hexo.io/zh-cn/docs/configuration" target="_blank" rel="noopener">HEXO官网</a>获取更多详细配置。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Hexo Configuration</span></span><br><span class="line"><span class="comment">## Docs: https://hexo.io/docs/configuration.html</span></span><br><span class="line"><span class="comment">## Source: https://github.com/hexojs/hexo/</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 网站标题</span></span><br><span class="line">title: VOSAMO</span><br><span class="line"><span class="comment"># 网站副标题</span></span><br><span class="line">subtitle:</span><br><span class="line"><span class="comment"># 网站描述</span></span><br><span class="line">description:</span><br><span class="line">keywords:</span><br><span class="line"><span class="comment"># 作者名字</span></span><br><span class="line">author: vosamo</span><br><span class="line"><span class="comment"># 语言</span></span><br><span class="line">language: zh-Hans</span><br><span class="line"><span class="comment"># 时区，Hexo 默认使用您电脑的时区</span></span><br><span class="line">timezone:</span><br><span class="line"></span><br><span class="line"><span class="comment"># URL</span></span><br><span class="line"><span class="comment">## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'</span></span><br><span class="line"><span class="comment"># 网址</span></span><br><span class="line">url: http://vosamo.gitee.io</span><br><span class="line"><span class="comment"># 网站根目录</span></span><br><span class="line">root: /blog/</span><br><span class="line">permalink: :year/:month/:day/:title/</span><br><span class="line">permalink_defaults:</span><br><span class="line"></span><br><span class="line">...</span><br><span class="line"></span><br><span class="line"><span class="comment"># Deployment</span></span><br><span class="line"><span class="comment">## Docs: https://hexo.io/docs/deployment.html</span></span><br><span class="line">deploy:</span><br><span class="line">  <span class="built_in">type</span>: git</span><br><span class="line">  <span class="comment"># 库（Repository）地址</span></span><br><span class="line">  repo: https://gitee.com/vosamo/blog.git</span><br><span class="line">  <span class="comment"># 静态文件保存的分支名称</span></span><br><span class="line">  branch: master</span><br></pre></td></tr></table></figure>
</li>
<li><p>生成页面</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hexo clean</span><br><span class="line">hexo g</span><br></pre></td></tr></table></figure>
</li>
<li><p>本地运行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">$ hexo s</span><br><span class="line">INFO  Start processing</span><br><span class="line">WARN  ===============================================================</span><br><span class="line">WARN  ========================= ATTENTION! ==========================</span><br><span class="line">WARN  ===============================================================</span><br><span class="line">WARN   NexT repository is moving here: https://github.com/theme-next</span><br><span class="line">WARN  ===============================================================</span><br><span class="line">WARN   It<span class="string">'s rebase to v6.0.0 and future maintenance will resume there</span></span><br><span class="line"><span class="string">WARN  ===============================================================</span></span><br><span class="line"><span class="string">INFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.</span></span><br></pre></td></tr></table></figure>
<p>在浏览器中访问<code>http://localhost:4000</code>就能看到博客主页了。</p>
</li>
<li><p>部署</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo d</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>​<br>  执行<code>hexo d</code>命令将静态文件部署到gitee的master分支。</p>
<h2 id="备份"><a href="#备份" class="headerlink" title="备份"></a>备份</h2><p>查看项目的<code>/gitignore</code>文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ cat .gitignore</span><br><span class="line">.DS_Store</span><br><span class="line">Thumbs.db</span><br><span class="line">db.json</span><br><span class="line">*.<span class="built_in">log</span></span><br><span class="line">node_modules/</span><br><span class="line">public/</span><br><span class="line">.deploy*/</span><br></pre></td></tr></table></figure>
<p>上述文件中的内容在<code>git commit</code>的时候都会被忽略。除此之外的文件就是需要备份的源文件，你只需要执行下面几步，就能完成备份：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git add .</span><br><span class="line">git commit -m <span class="string">'blog backup'</span></span><br><span class="line">git push origin hexo</span><br></pre></td></tr></table></figure>
<p>这样每次写作的时候，只需要执行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo cl</span><br><span class="line">hexo g</span><br><span class="line">hexo d</span><br></pre></td></tr></table></figure>
<p>完成静态文件同步部署</p>
<p>以及</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git add xxx</span><br><span class="line">git commit -m <span class="string">'xxx'</span></span><br><span class="line">git push origin hexo</span><br></pre></td></tr></table></figure>
<p>完成博客源文件备份。</p>
<h2 id="恢复"><a href="#恢复" class="headerlink" title="恢复"></a>恢复</h2><p>假如你想从博客备份源文件恢复，你需要保证你的电脑上安装了nodejs、Hexo，然后按照以下步骤操作：</p>
<ul>
<li><p>将源文件克隆到本地</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> git@gitee.com:vosamo/blog.git</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>切换到博客目录，安装package</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install</span><br><span class="line">npm install hexo-deployer-git</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>恢复博客</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hexo cl &amp; hexo g</span><br><span class="line">hexo s</span><br></pre></td></tr></table></figure>
</li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Hexo/" rel="tag"># Hexo</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/02/19/使用Hexo写博客/" rel="prev" title="使用Hexo写博客">
                使用Hexo写博客 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/blog/images/avatar.gif" alt="vosamo">
            
              <p class="site-author-name" itemprop="name">vosamo</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#环境准备"><span class="nav-number">1.</span> <span class="nav-text">环境准备</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装NodeJS"><span class="nav-number">1.1.</span> <span class="nav-text">安装NodeJS</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装Git"><span class="nav-number">1.2.</span> <span class="nav-text">安装Git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装Hexo"><span class="nav-number">1.3.</span> <span class="nav-text">安装Hexo</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#创建博客项目"><span class="nav-number">2.</span> <span class="nav-text">创建博客项目</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#申请注册码云账号。"><span class="nav-number">2.1.</span> <span class="nav-text">申请注册码云账号。</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建项目"><span class="nav-number">2.2.</span> <span class="nav-text">创建项目</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#开启Page服务"><span class="nav-number">2.3.</span> <span class="nav-text">开启Page服务</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置SSH"><span class="nav-number">2.4.</span> <span class="nav-text">配置SSH</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建博客"><span class="nav-number">2.5.</span> <span class="nav-text">创建博客</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#备份"><span class="nav-number">2.6.</span> <span class="nav-text">备份</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#恢复"><span class="nav-number">2.7.</span> <span class="nav-text">恢复</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vosamo</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
